﻿#include "liveMedia.hh"
#include "BasicUsageEnvironment.hh"

//extern netAddressBits SendingInterfaceAddr = inet_addr("192.168.1.46");

int main(void)
{
	TaskScheduler* scheduler = BasicTaskScheduler::createNew();
	BasicUsageEnvironment* env = BasicUsageEnvironment::createNew(*scheduler);
	UserAuthenticationDatabase* authDB = NULL;
#if 0
#endif

	RTSPServer* rtspServer = RTSPServer::createNew(*env, 554,authDB);//创建一个rtsp服务
	if (rtspServer == NULL)
	{
		*env << "Failed to create RTSP server:" << env->getResultMsg() << "\n";
		exit(-1);
	}

	char const* descriptionString = "aac rtsp server";
	char const* streamName = "aactest";
	char const* inputFileName = "nocturne.aac";

	/*
	1. 创建一个媒体会话
	2. 创建一个子会话并添加
	3. 添加媒体会话到服务中

    1. 一个媒体服务中可以存在多个媒体会话
	*/
	ServerMediaSession* serverMediaSession_aac
		= ServerMediaSession::createNew(*env, streamName, streamName, descriptionString);//创建一个媒体会话

	serverMediaSession_aac->addSubsession(ADTSAudioFileServerMediaSubsession::createNew(*env, inputFileName, false));
	//针对aac 文件创建一个对应的 ADTSAudioFileServerMediaSubsession 子会话

	rtspServer->addServerMediaSession(serverMediaSession_aac);//服务中添加子会话



	(*env) << "acc test url:" << rtspServer->rtspURL(serverMediaSession_aac) << "\n";

#ifdef DEBUG
	(*env) << "acc 1111111111111111111111test url:" << rtspServer->rtspURL(serverMediaSession_aac) << "\n";
#endif // DEBUG

	//sscanf() 里面还可以使用正则表达式



	char const* descriptionString_264 = "264 rtsp server";
	char const* streamName_264 = "264test";
	char const* inputFileName_264 = "sintel.264";

	ServerMediaSession* serverMedaiSession_264
		= ServerMediaSession::createNew(*env, streamName_264, streamName_264, descriptionString_264);

	serverMedaiSession_264->addSubsession(H264VideoFileServerMediaSubsession::createNew(*env, inputFileName_264, false));

	rtspServer->addServerMediaSession(serverMedaiSession_264);

	//OutPacketBuffer::maxSize = 100000;// allow for some possibly large H.264 frames
	(*env) << "acc test url:" << rtspServer->rtspURL(serverMedaiSession_264) << "\n";



	env->taskScheduler().doEventLoop();

	return 0;
}